import sys
import socket
import cPickle as pickle
def getconf():
	conf = {}
	FILE = open("./serv.conf",'r')
	for line in FILE:
		line = line.strip()
		print line.split(":")
		conf[line.split(":")[0]]=line.split(":")[1]
	return conf	
def serv(conf):
	current={}
	port = int(conf["port"])
	print port
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sock.bind((socket.gethostname(),port))
	sock.listen(5)
	while True:
		c,addr = sock.accept()
		print 'got connection from ', addr
		code=c.recv(5)
		print code
		if code=="spite":
			#spitter
			FILE = c.makefile()	
			data = pickle.load(FILE)
			current=data
			print data.keys()
			FILE.close()
		else:
			#webby
			print "##############################################"	
			FILE=c.makefile()
			pickle.dump(current,FILE)
			FILE.close()
			
		

conf = getconf()
serv(conf)
